package com.wx.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wx.common.CreateValidate;
import com.wx.common.PageParam;
import com.wx.common.WrapMapper;
import com.wx.common.Wrapper;
import com.wx.domain.dto.SysPatientFollowDto;
import com.wx.domain.vo.PatientInquiryDetailVo;
import com.wx.entity.SysNotepad;
import com.wx.holder.WxUserHolder;
import com.wx.service.SysNotepadService;
import com.wx.utils.SnowFlakeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

/**
 * <p>Title:      SysNotepadController. </p>
 * <p>Description  记事本管理</p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company:    医百科技有限公司 </p>
 *
 * @author         <a href="yangwensheng@100doc.com.cn"/>杨文生</a>
 * @since      2021/6/19 14:06
 */
@RestController
@RequestMapping(value = "/notepad", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(tags = "记事本管理", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class SysNotepadController {

    @Resource
    private SysNotepadService sysNotepadService;

    /**
     * 导出临时问询明细
     *
     * @param response
     * @param SysNotepad
     * @throws IOException
     */
    @PostMapping(value = "/export")
    @ApiOperation(httpMethod = "POST", value = "导出临时问询明细")
    public void exportInquiryDetail(HttpServletResponse response, @ApiParam(name = "SysNotepad", value = "SysNotepad") @RequestBody SysNotepad SysNotepad) throws IOException {
        List<SysNotepad> sysNotepads = sysNotepadService.listPage(SysNotepad);
        //添加响应头信息
        response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("临时问询明细.xlsx", "UTF-8"));
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        //获取数据
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        //设置背景颜色
        headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
        //设置头字体
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setFontHeightInPoints((short) 15);
        headWriteFont.setBold(true);
        headWriteCellStyle.setWriteFont(headWriteFont);
        //设置头居中
        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        //内容策略
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        //设置 水平居中
        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
        EasyExcel.write(response.getOutputStream(), SysNotepad.class).registerWriteHandler(horizontalCellStyleStrategy)
                .sheet("临时问询明细").doWrite(sysNotepads);
    }
}
